/*********************************************************************
 *
 * Software License Agreement ()
 *
 *  Copyright (c) 2020, HINS, Inc.
 *  All rights reserved.
 *
 * Author: Hu Liankui
 * Create Date: 8/9/2020
 *********************************************************************/

/**
 * @brief 兴颂激光雷达驱动
 */

#pragma once

#include "hins/laser_data_receiver.h"
#include <set>
namespace hins
{

  class XingSongDriver;
  using XingSongDriverHdr = std::shared_ptr<XingSongDriver>;

  class XingSongDriver
  {
  public:
    XingSongDriver(const ConnectionAddress &conn_info);
    XingSongDriver(const ConnectionAddress &conn_info, ShadowsFilterParam shadows_filter_param_);
    ~XingSongDriver();

    bool StartCapturingTCP();

    ScanData GetFullScan();
    
    bool Connect()
    {
      return data_receiver_ptr_->Connect();
    }

    bool IsConnected()
    {
      return data_receiver_ptr_->IsConnected();
    }

    void Disconnect()
    {
      data_receiver_ptr_->Disconnect();
    }

    int SyncWrite(const std::array<unsigned char, 12> command)
    {
      return data_receiver_ptr_->SyncWrite(command);
    }

  private:
    void RunMain();
    void ShadowsFilterInit(int scan_num);
    void ShadowsFilter(ScanData& data, int scan_num);
  
  private:
    ShadowsFilterParam shadows_filter_param_;
    ConnectionAddress conn_info_;
    LaserDataReceiverPtr data_receiver_ptr_;
    std::thread guard_thread_;
    std::vector<float> shadows_filter_threshold_min_;
    std::vector<float> shadows_filter_threshold_max_;
    set<int> shadows_del_index_;
  };


}
